#pragma once

#include <time.h>
// ANSI颜色
#define ANSI_RESET "\033[0m"   // 默认颜色
#define ANSI_RED "\033[1;31m"  // 红色加粗
#define ANSI_BLUE "\033[1;34m" // 蓝色加粗
#define ANSI_DEFAULT "\033[0m" // 默认颜色

#define LDBG 0
#define LINF 1
#define LERR 2
#define LDEFAULT LINF

#define LOG(level, color, format, ...)                                          \
    {                                                                           \
        if (level >= LDEFAULT)                                                  \
        {                                                                       \
            time_t t = time(NULL);                                              \
            struct tm *lt = localtime(&t);                                      \
            char time_tmp[32] = {0};                                            \
            strftime(time_tmp, 31, "%m-%d %T", lt);                             \
            fprintf(stdout, "%s[%d][%s][%s:%d] " format ANSI_RESET "\n",        \
                    color, level, time_tmp, __FILE__, __LINE__, ##__VA_ARGS__); \
        }                                                                       \
    }

// 设置各等级日志颜色
#define DLOG(format, ...) LOG(LDBG, ANSI_DEFAULT, format, ##__VA_ARGS__)
#define ILOG(format, ...) LOG(LINF, ANSI_BLUE, format, ##__VA_ARGS__)
#define ELOG(format, ...) LOG(LERR, ANSI_RED, format, ##__VA_ARGS__)
